<template lang="html">
    <div class="messageadd">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;新增消息</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-form ref="form" label-width="120px">
                <el-form-item label="类型：">
                    <el-select v-model="id" @change="changeType" placeholder="请选择类型">
                        <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="内容(中文)：">
                    <el-input v-model="contentCn" placeholder="请输入中文内容" ></el-input>
                </el-form-item>
                <el-form-item label="内容(英文)：">
                    <el-input v-model="contentEn" placeholder="请输入英文内容" ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="width:150px" type="primary" @click="submit()">新增</el-button>
                    <router-link to="/message"><el-button style="width:150px" type="primary">返回列表</el-button></router-link>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import {postMessageAdd} from '@/api/message/list'
    export default {
        name: "messageadd",
        components:{
           
        },
        data() {
            return {
                contentCn:'',//中文内容
                contentEn:'',//英文内容
                id:'',//类型id
                options:[
                    {
                        value:1,
                        label:"系统"
                    },
                    {
                        value:2,
                        label:"交易"
                    }
                ],
            }
        },
        created(){

        },
        mounted() {
            
        },
        methods: {
            //确认提交修改  
            submit(){
                if(this.id == ''){
                    this.$message({
                        message: '请选择类型！',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.contentCn == ''){
                    this.$message({
                        message: '请输入中文内容！',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.contentEn == ''){
                    this.$message({
                        message: '请输入英文内容！',
                        type: 'warning'
                    });
                    return false;
                }
                //添加
                postMessageAdd(this.id,this.contentCn,this.contentEn).then(res => {
                    if(res.code == 200){
                        this.$message({
                            message: '新增成功！',
                            type: 'success'
                        });
                    }else {
                        this.$message.error('新增失败！');
                    }
                })
            },
            //保存类型id
            changeType(id){
                this.id = id;
            },  
        }
    }
</script>

<style lang="css">

</style>
